package com.atguigu.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class OrderConfirmVO {
    @Setter
    @Getter
    private List<MemberAddressVo> address; //会员收货地址 ums_member_receive_address

    @Setter
    @Getter
    private List<OrderItemVo> orderItems; //所有选中的商品信息

    //发票信息

    //优惠券信息
    @Setter
    @Getter
    private Integer integration;

    @Setter
    @Getter
    Map<Long, Boolean> stocks;

    @Setter
    @Getter
    String orderToken; //防重令牌

    public Integer getCount() {
        Integer i = 0;
        if(orderItems != null) {
            for (OrderItemVo orderItem : orderItems) {
               i+=orderItem.getCount();
            }
        }
        return i;
    }

//    private BigDecimal total;  //订单总额

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if(orderItems != null) {
            for (OrderItemVo orderItem : orderItems) {
                BigDecimal multiply = orderItem.getPrice().multiply(new BigDecimal(orderItem.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice(){
        return getTotal();
    } //实际应付金额

}
